// newHousePackage/pages/newHouseDetail/newHouseDetail.js
import {
  queryNewHouseDetail,
  queryNewHouseOtherDetail,
  queryNewHouseExpert,
  queryNewHouseComment,
  approveComment,
  createComment,
  deleteComment,
  queryHouseQrCode,
  settingHouseRemind,
  expertPhoneAction
} from "../../../service/house_service"

import { loginWxAction, queryOnlineCustomer } from "../../../service/config"
import { attentionAction } from "../../../service/attention_service"

import { bindUserRelation } from "../../../service/user_service"
import { agentEnterNewHouse, queryCompanyHouseResident } from "../../../service/platform_service"
import debounce from "../../../tools/debounce"
import { MAP_KEY } from "../../../service/base_service"
import { queryStoreDetail, queryBaseDetail } from "../../../service/onetoone_service"
// let QQMapWX = require('../../../sdk/qqmap-wx-jssdk1.2/qqmap-wx-jssdk');
// let qqmapsdk;
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    showSharePop: false,
    isLogin: false,
    keyBoardHeight: 0,
    showEmptySharePop: false,//没有共享组的情况，创建共享组
    swiperAutoplay: false,
    swiperInterval: 2000,
    swiperDuration: 500,
    singleFormatShowText: "暂无",//单独的户型显示字段
    currentSwiperIndex: 0,//当前swiper下标
    isShowCommentPop: false,//评论弹窗
    //地图key -- 地图相关
    mapSubkey: MAP_KEY,
    latitude: "",
    longitude: "",
    enable3d: false,
    showCompass: false,
    enableOverlooking: false,
    enableZoom: false,
    enableScroll: false,
    enableRotate: false,
    drawPolygon: false,
    enableSatellite: false,
    enableTraffic: false,
    markers: [{
      id: 0,
      iconPath: "/img/common/dingwei.png",
      latitude: "",
      longitude: "",
      width: 24,
      height: 24,
      callout: {

      }
    }],
    tempCommissionList: [
      { type: 1 }, { type: 1 }
    ],
    nearestSubWayText: "",//最近地铁信息
    showRulePopup: false,
    showPopupTitle: "推荐规则",
    showRuleContent: "",
    scanExpert: {},//是否有扫描的经纪人
    scrollRefreshStatus: true,
    changePriceTitle: "变价提醒",
    changeOpenTimeTitle: "售卖提醒",
    //吸顶参数
    scrollTop: 0,
    offsetTop: 0,
    toView: "",
    //吸顶参数
    //顶部信息骨架屏配置
    topRowWidths: [
      "60%", "100%"
    ],

    topBanners: [

    ],
    tempTags: [
      {
        title: "未开盘",
        status: 1,
      },
      {
        title: "低单价",
        status: 0,
      },
      {
        title: "低总价",
        status: 0,
      },
      {
        title: "多轨交汇",
        status: 0,
      },
      {
        title: "环线房",
        status: 0,
      },
    ],
    ratingValue: 4,//评论评星
    loadingStatus: false,//数据加载状态
    horizontalModules: [
      { title: "户型", isShow: true }, { title: "资料", isShow: true }, { title: "佣金", isShow: true }, { title: "配套", isShow: true },
      { title: "总平", isShow: true }, { title: "专家", isShow: true }, { title: "动态", isShow: true }, { title: "评论", isShow: true },
    ],
    horizontalSwiperIndex: 100,//默认户型
    houseTypeChangeArr: [

    ],//户型切换数组
    houseTypeList: [

    ],
    houseTypeChangeIndex: 0,//户型默认第一个

    attachFiles: [],//项目资料
    settingRoleRelation: [],//佣金列表
    commentList: [

    ],
    //动态列表
    houseDynamicList: [

    ],
    expertArr: [

    ],
    tempHouseTimeAxiss: [
      { type: 1, status: 0 }, { type: 1, status: 1 }, { type: 1, status: 0 }, { type: 1, status: 0 }
    ],

    houseNumber: null,//房源编号
    houseDetail: {},//新房详情
    formats: [],//户型数组
    //创建评论参数
    createCommentData: {
      content: "",
      images: [],
      houseNumber: "",
      parentId: "",
      grandId: "",
    },
    //评论的点击数据，评论成功后，直接强更，不去这个拉取列表
    commentData: {},
    commentType: "main",//main是代表一级评论，sub是代表二级带回复的评论
    //一级评论的index:
    oneLevelIndex: 0,
    currentSearchTitle: "公交",
    currentBottomIndex: 0,
    mapSearchList: [],
    changeTypeList: [
      {
        title: "公交",
        icon: "./../../img/mapgongjiao.png"
      },
      {
        title: "学校",
        icon: "./../../img/mapxuexiao.png"
      },
      {
        title: "餐饮",
        icon: "./../../img/mapcanyin.png"
      },
      {
        title: "购物",
        icon: "./../../img/mapgouwu.png"
      },
      {
        title: "医院",
        icon: "./../../img/mapyiyuan.png"
      }
    ],
    enterModles: [
      {
        title: "全部户型",
        path: "../../img/houseDetail/dquanbhx_icon.png",
        url: "../houseAllHouseTypes/houseAllHouseTypes",
      },
      {
        title: "楼盘动态",
        path: "../../img/houseDetail/dloupandt_icon.png",
        url: "../houseAllDyn/houseAllDyn",
      },
      {
        title: "楼盘详情",
        path: "../../img/houseDetail/dloupanxiangq_icon.png",
        url: "../houseMoreInfo/houseMoreInfo",
      },
      {
        title: "楼盘图片",
        path: "../../img/houseDetail/dloupantp_icon.png",
        url: "../houseAllImgs/houseAllImgs",
      },
      {
        title: "周边配套",
        path: "../../img/houseDetail/dzhoubpeitao_icon.png",
        url: "../houseMapAround/houseMapAround",
      },

    ],
    // 共享相关参数
    newShareName: "",//新建共享组名称
    shareList: [

    ],
    showExpertPop: false,//咨询置业顾问弹窗
    bindUserId: "",//绑定关系的userId,
    isScanEnter: false,//是否是扫码进来的
    isShare: false,//是否分享进来的
    roleType: 1,//角色等级
    zhuChangeArr: [],
    videoArr: [],//房源视频arr;
    allTopImgArr: [],//房源所有图片arr
    houseTypeIndex: 0,
    scrollTopValue: 0,//到顶部距离
    bindHouse: 0,//是否是绑定房源进来的
    selectCompanyNumber: "",//选中的代理公司
    residentArr: [],//驻场arr
    cityName: "",
    sameHouseList: [
      { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }
    ],
    communityNumber: null,
    communityHouseList: [],//同小区房源



    // 新活动详情参数=============
    tempTags: [
      "插花教学", "书法练习", "围炉茶话", "网红打卡"
    ],

    detailId: null,
    onlineCustomer: {},
    mealList: [], // 套餐列表
    selectMealData: {},//选中的套餐
    showMealPop: false,
    isFriend: 0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let lanuchObj = wx.getLaunchOptionsSync();
    if (options.isFriend && options.isFriend == 1) {
      this.setData({
        isFriend: 1,
        houseNumber: options.houseNumber,
      })
    }
    if (lanuchObj.scene == 1155) {
      this.setData({
        isFriend: 0,
        isShare: true,
      })
    }
    if (this.data.isFriend == 1) {
      return;
    }

    if (options.houseNumber) {
      this.setData({
        houseNumber: options.houseNumber,
        // communityNumber: options.communityNumber
      })
    }
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    //是从绑定房源进来的
    if (options.bindHouse == 1) {
      this.setData({
        bindHouse: 1
      })
    }
    // // 实例化API核心类
    // qqmapsdk = new QQMapWX({
    //   key: this.data.mapSubkey
    // });

    //扫码进来的
    if (options.scene) {
      let scene = decodeURIComponent(options.scene)
      console.log("JJLog:9999999===:" + scene);
      let sceneArray = scene.split("&");
      let firstArr = sceneArray[0].split("=");
      let secondArr = sceneArray[1].split("=");
      let threeArr = sceneArray[2].split("=");
      let b = secondArr[1];
      let houseNumber = firstArr[1];
      if (b == 1) {
        this.setData({
          isScanEnter: true
        })
      }
      let userId = threeArr[1];
      this.setData({
        bindUserId: userId,
        isShare: true,
        houseNumber: houseNumber
      })

      this.userWxLogin();

      return;
    }
    if (options.isShare) {
      this.setData({
        isScanEnter: false,
        isShare: true,
        bindUserId: options.userId,
      })
      this.userWxLogin();

      return;
    }
    // 获取基地详情
    this.queryBaseDetail();
    // 获取在线客服
    this.queryOnlineCustomer();

    if (!app.globalData.openId) {
      app.globalData.openId = wx.getStorageSync('openId');
    }



  },
  queryOnlineCustomer() {
    queryOnlineCustomer().then(res => {
      console.log("JJLog:获取到的客服是:" + JSON.stringify(res));
      if (res.code == 200) {
        if (res.data) {
          this.setData({
            onlineCustomer: res.data
          })
          let arr = [];
          arr.push(res.data);
          this.setData({
            expertArr: arr,
          })
        }
      }
    }).catch(err => {
      this.setData({
        onlineCustomer: {},
      })
    })
  },


  //用户登陆授权等:
  userWxLogin() {
    loginWxAction().then((res => {
      console.log("JJLog:登录返回:" + JSON.stringify(res));
      let data = res.data.data;
      if (res.code == 200) {
        app.globalData.nickName = data.nickName;
        app.globalData.avatar = data.avatar;
        app.globalData.name = data.name || "";
        app.globalData.phone = data.phone || "";
        app.globalData.isLogin = data.isLogin;
        app.globalData.userId = data.id;
        app.globalData.qrCode = data.qrCode || "";
        app.globalData.isAuthUserInfo = data.isAuthUserInfo;
        app.globalData.weChat = data.weChat || "";
        app.globalData.roleName = data.roleName || "";
        app.globalData.companyName = data.companyName || "";
        app.globalData.companyNumber = data.companyNumber || "";
        app.globalData.openId = data.openId;
        //绑定挂级关系:
        if (this.data.bindUserId) {
          this.bindUserRelation();
        }
        this.queryBaseDetail();
      }
    })).catch(err => {
      console.error("JJLog:userWxLogin", err);
    })
  },


  //绑定挂级关系:
  bindUserRelation() {
    let type = 1;
    if (this.data.isScanEnter) {
      type = 1;
    } else {
      type = 2;
    }
    bindUserRelation(type, this.data.bindUserId, this.data.houseNumber).then(res => {
      console.log("JJLog:绑定挂级关系:" + JSON.stringify(res));
      if (res.code == 200) {
        // this.queryNewHouseExpert();

      }
    }).catch(err => {
      console.error("JJLog:bindUserRelation:", err);
    })
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
    this.setData({
      isLogin: app.globalData.isLogin
    })
    this.setData({
      roleType: app.globalData.roleType || 1
    })
  },

  //查询房源二维码
  queryHouseQrCode() {
    queryHouseQrCode(this.data.houseNumber, 2).then(res => {
      console.log("JJLog:房源二维码是:" + JSON.stringify(res));
      if (res.code == 200) {
        app.globalData.houseQrCode = res.data || "";
      }
    }).catch(err => {
      console.error("JJLog:queryHouseQrCode", err);
      app.globalData.houseQrCode = "";
    })
  },

  //查询新商品详情:
  queryBaseDetail() {
    wx.showLoading();
    queryBaseDetail(this.data.houseNumber).then(res => {
      console.log("JJLog:基地详情是=====:" + JSON.stringify(res));
      wx.hideLoading();
      this.setData({
        scrollRefreshStatus: false,
      })
      if (res.code == 200) {
        this.setData({
          loadingStatus: true,
          houseDetail: res.data,
          latitude: res.data.latitude,
          longitude: res.data.longitude,
        })
        let callout = {
          content: "",
          color: "#FFFFFF",
          fontSize: "20rpx",
          padding: 10,
          borderRadius: 10,
          bgColor: "#FF0000",
          display: "ALWAYS"
        };
        callout.content = "基地位置";
        this.setData({
          ['markers[' + 0 + '].latitude']: res.data.latitude,
          ['markers[' + 0 + '].longitude']: res.data.longitude,
          ['markers[' + 0 + '].callout']: callout,
        })
        this.houseDataDeal(res.data);
      }
    }).catch(err => {
      wx.hideLoading();
      console.error("JJLog:queryBaseDetail", err);
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
    })
  },
  // 显示选择套餐弹窗:
  showSelectMealPop() {
    this.setData({
      showMealPop: true,
    })
  },
  // 选择套餐点击:
  selectMealAction(e) {
    let item = e.currentTarget.dataset.item;
    this.setData({
      selectMealData: item,
      showMealPop: false,
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    //显示顶部刷新图标
    // wx.showNavigationBarLoading();
    this.refreshPageMethod();
    console.log("JJLog:下拉刷新开始了===");
    //要刷新请求服务器的方法
    // this.selectCar();
    //隐藏导航栏加载框
    // wx.hideNavigationBarLoading();
    //停止下拉事件
    // wx.stopPullDownRefresh();
  },

  //下拉刷新页面方法
  refreshPageMethod() {
    wx.showLoading({
      title: '刷新中...',
    })
    setTimeout(() => {
      wx.hideLoading();
      wx.stopPullDownRefresh();
    }, 2000);
  },

  //顶部swiper切换方法:
  topImgSwiperChange(e) {
    this.setData({
      currentSwiperIndex: e.detail.current
    })
  },


  //跳转到贷款计算器页面:
  pushToCalculateAction() {
    let priceType = 1;//以房屋总价为计算类型
    let totalPrice = this.data.houseDetail.totalPrice;

    wx.navigateTo({
      url: '/firstPackage/pages/calculatorLoans/calculatorLoans?priceType=' + priceType + "&totalPrice=" + totalPrice,
    })
  },




  //户型切换点击:
  houseTypeChangeActions(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      houseTypeChangeIndex: index,
      houseTypeList: this.data.formats[index]
    })

  },

  //楼盘动态图片预览
  previewDynImg(e) {
    let index = e.currentTarget.dataset.index;
    let type = e.currentTarget.dataset.type;
    let cIndex = e.currentTarget.dataset.cindex;
    let arr = [];
    if (type == "dyn") {
      arr = this.data.houseDynamicList;
    }
    let pic = arr[cIndex].pics[index].url;
    let pics = arr[cIndex].pics;
    let urls = [];
    pics.forEach((item) => {
      urls.push(item.url);
    })

    wx.previewImage({
      current: pic,
      urls: urls,
    })
  },

  //户型关注操作
  formatCollectAction(e) {
    console.log("JJLog:关注回调:" + JSON.stringify(e));
    let { formatNumber, isCollect, index } = e.detail;
    this.attentionAction(formatNumber, isCollect, index)
  },
  //关注操作
  attentionAction(formatNumber, isCollect, index) {
    let data = {
      collectType: 7,
      number: formatNumber,
    }
    wx.showLoading();
    attentionAction(data).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        if (isCollect) {
          wx.showToast({
            title: '取关成功',
            icon: "success"
          })
        } else {
          wx.showToast({
            title: '关注成功',
            icon: "success"
          })
        }
        //动态数组:
        let item = 'houseTypeList[' + index + '].isCollection';
        this.setData({
          [item]: !isCollect,
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:attentionAction", err);
    })
  },

  //添加一个楼盘到对比列表
  addHouseCompare() {
    let houseNumber = this.data.houseDetail.houseNumber;
    wx.navigateTo({
      url: '/formPackage/pages/houseCompare/houseCompareList/houseCompareList?houseNumber=' + houseNumber,
    })
  },








  // 事件触发，调用接口
  nearby_search: function () {
    let _this = this;
    // qqmapsdk.search({
    //   keyword: _this.data.currentSearchTitle, //搜索关键词
    //   location: this.data.latitude + "," + this.data.longitude,
    //   success: function (res) { //搜索成功后的回调
    //     // console.log("JJLog:当前搜索结果是=====:" + JSON.stringify(res));
    //     if (res.data && res.data.length > 0) {
    //       let arr = res.data.slice(0, 3);;
    //       _this.setData({
    //         mapSearchList: arr
    //       })
    //     }

    //   },
    //   fail: function (res) {
    //     console.log(res);
    //   },
    //   complete: function (res) {
    //     console.log(res);
    //   }
    // });
  },
  //周边地铁请求:
  nearby_searchSubWay: function () {
    let _this = this;
    // qqmapsdk.search({
    //   keyword: "地铁", //搜索关键词
    //   location: this.data.latitude + "," + this.data.longitude,
    //   success: function (res) { //搜索成功后的回调
    //     console.log("JJLog:地铁搜索结果是=====:" + JSON.stringify(res));
    //     if (res.data && res.data.length > 0) {
    //       let item = res.data[0];
    //       let distanceArr = (JSON.stringify(item._distance)).split(".");
    //       let distanceText = distanceArr[0];
    //       let text = "距" + item.address + item.title + distanceText + "米"
    //       _this.setData({
    //         nearestSubWayText: text
    //       })
    //     }

    //   },
    //   fail: function (res) {
    //     console.log(res);
    //   },
    //   complete: function (res) {
    //     console.log(res);
    //   }
    // });
  },
  //周边配套类型切换:
  mapCoverChangeAction(e) {
    let index = e.currentTarget.dataset.index;

    let arr = this.data.changeTypeList;
    let title = "";
    arr.forEach((item, idx) => {
      item.isChoose = false;
      if (index == idx) {
        item.isChoose = true;
        title = item.title;
      }
    })
    this.setData({
      changeTypeList: arr,
      currentSearchTitle: title,
      currentBottomIndex: index
    })
    this.nearby_search();
  },

  //详情数据处理:
  houseDataDeal(data) {
    //1.图片，视频显示处理 
    //顶部轮播图处理: 只要这个视频 加上 封面 加上 效果图

    this.setData({
      topBanners: data.images || [],
    })
    if (this.data.topBanners.length < 1) {
      let imgArr = [];
      let obj = {
        type: 1,
        url: data.coverPic
      }
      imgArr.push(obj)
      this.setData({
        topBanners: imgArr
      })
    }
    if (data.contacts && data.contacts.length > 0) {
      this.setData({
        expertArr: data.contacts
      })
    }
    // let tags = [];
    // if(data.keyword){
    //   tags.push(data.keyword)
    // }
    // this.setData({
    //   'houseDetail.tags':tags
    // })
    return;

    // 处理底部经纪人显示:
    let expertData = {
      avatar: "",
      openId: "",
      name: "",
      phone: "",
    }
    expertData.avatar = data.pushAvatar;
    expertData.name = data.pushName;
    expertData.openId = data.pushOpenId;
    expertData.phone = data.pushPhone;
    this.setData({
      scanExpert: expertData
    })

  },
  //获取房源的其它数据:
  queryNewHouseOtherDetail() {
    queryNewHouseOtherDetail(this.data.houseNumber).then(res => {
      console.log("JJLog:楼盘其它数据:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          houseDynamicList: res.data.dynamics || [],
          attachFiles: res.data.attachFiles || [],
          settingRoleRelation: res.data.settingRoleRelation || []
        })
        this.dealShowOtherInfo();
      }
    }).catch(err => {
      console.warn("JJLog:楼盘其它信息获取失败:" + JSON.stringify(err));
    })
  },
  dealShowOtherInfo() {
    if (this.data.houseDynamicList.length < 1) {
      let dynItem = 'horizontalModules[' + 6 + '].isShow';
      this.setData({
        [dynItem]: false,
      })
    }
    if (this.data.attachFiles.length < 1) {
      let fileItem = 'horizontalModules[' + 1 + '].isShow';
      this.setData({
        [fileItem]: false,
      })
    }
    if (this.data.settingRoleRelation.length < 1) {
      let setItem = 'horizontalModules[' + 2 + '].isShow';
      this.setData({
        [setItem]: false,
      })
    }
  },
  //获取房源经纪人:
  queryNewHouseExpert() {
    return;
    queryNewHouseExpert(this.data.houseNumber, "").then(res => {
      console.log("JJLog:楼盘经纪人列表:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          expertArr: res.data.list || [],
          scanExpert: res.data.scanExpert
        })
        if (this.data.expertArr.length < 1) {
          let expertItem = 'horizontalModules[' + 5 + '].isShow';
          this.setData({
            [expertItem]: false,
          })
        }
        if (res.data.list && res.data.list.length > 3) {
          let arr = res.data.list.slice(0, 3)
          this.setData({
            expertArr: arr
          })
        }

      }
    }).catch(err => {
      console.error("JJLog:楼盘置业顾问列表失败:" + JSON.stringify(err));
    })
  },

  //获取房源的评论列表:
  queryNewHouseComment() {
    queryNewHouseComment(this.data.houseNumber).then(res => {
      console.log("JJLog:楼盘评论列表:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          commentList: res.data
        })
      }
    }).catch(err => {
      console.error("JJLog:楼盘评论列表失败:" + JSON.stringify(err));
    })
  },
  // 跳转到兑换
  pushToExchangeAction() {
    app.globalData.mealData = this.data.selectMealData; // 套餐全局赋值传下去
    wx.navigateTo({
      url: '/shopMallPackage/pages/exchangeActivity/exchangeActivity?id=' + this.data.houseDetail.id,
    })
  },

  //咨询首付详情
  callPhoneAction() {
    wx.makePhoneCall({
      phoneNumber: this.data.scanExpert.phone,
      fail: err => {

      }
    })
  },



  //跳转到房源位置
  pushAavigationAdd() {
    let latitude = this.data.houseDetail.latitude;
    let longitude = this.data.houseDetail.longitude;
    wx.openLocation({
      latitude,
      longitude,
      scale: 15,
      name: "",
      address: this.data.houseDetail.address
    })
  },



  //创建一条新评论
  createNewComment() {
    this.setData({
      isShowCommentPop: true,
      commentType: 'refresh',//不用去本地回填数据，直接这个刷新列表
    })
  },
  //创建二级评论:
  createTwoLevelComment(e) {
    console.log("JJLog:===:" + JSON.stringify(e));
    let item = e.detail.data;
    let type = e.detail.type;
    let index = e.detail.index;
    if (app.globalData.openId == item.openId) {
      wx.showModal({
        title: '提示',
        content: '是否删除该评论',
        confirmColor: "#FF0000",
        success: res => {
          if (res.confirm) {
            this.deleteOneComment(item.id)
          }
        }
      })
      return;
    }
    if (type == "main") {
      this.setData({
        'createCommentData.parentId': item.id,
        "createCommentData.grandId": item.id,
        oneLevelIndex: index,
        commentData: item,
        commentType: type
      })
    } else {
      //回复:

    }
    this.setData({
      isShowCommentPop: true
    })
  },
  //创建三级评论:
  createThreeLevelComment(e) {
    let item = e.detail.data;
    let type = e.detail.type;
    let index = e.detail.index;
    let id = e.detail.id;//grandId始终是一级的评论的id
    if (app.globalData.openId == item.openId) {
      wx.showModal({
        title: '提示',
        content: '是否删除该评论',
        confirmColor: "#FF0000",
        success: res => {
          if (res.confirm) {
            this.deleteOneComment(item.id)
          }
        }
      })
      return;
    }

    this.setData({
      'createCommentData.parentId': item.id,
      "createCommentData.grandId": id,
      oneLevelIndex: index,
      commentData: item,
      commentType: type
    })
    this.setData({
      isShowCommentPop: true
    })
    console.log("JJLog:现在是:" + JSON.stringify(this.data.createCommentData));
  },
  //发送评论:
  commentSend(e) {
    console.log("JJLog:评论信息是:" + JSON.stringify(e));
    let comment = e.detail.comment;
    this.setData({
      'createCommentData.content': comment,
      'createCommentData.houseNumber': this.data.houseNumber
    })
    debounce(this.sendCommentRequest);
  },
  sendCommentRequest() {
    wx.showLoading();
    createComment(this.data.createCommentData).then(res => {
      wx.hideLoading();
      console.log("JJLog:添加评论成功:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          isShowCommentPop: false
        })
        if (this.data.commentType == "refresh") {
          this.queryNewHouseComment();
        } else {
          //回复更新:
          this.updateOneLevelComment(res.data, this.data.commentType);
        }
      }
    }).catch(err => {
      console.error("JJLog:创建评论失败:" + JSON.stringify(err));
      wx.hideLoading();
      wx.showToast({
        title: err || "评论失败",
        icon: "none"
      })
    })
  },
  //删除评论:
  deleteOneComment(id) {
    wx.showLoading();
    deleteComment(id, this.data.houseNumber).then(res => {
      wx.hideLoading();
      console.log("JJLog:删除评论成功:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          commentList: res.data
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "删除失败",
        icon: "none"
      })
      console.error("JJLog:删除评论失败:" + JSON.stringify(err));
    })
  },
  //点赞评论;
  approveCommentAction(e) {
    let id = e.detail.id;
    let index = e.detail.index;
    let approveNum = this.data.commentList[index].approveNum + 1;
    wx.showLoading();
    approveComment(id).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        let item = 'commentList[' + index + '].approveNum';
        let approve = 'commentList[' + index + '].isApprove';
        this.setData({
          [item]: approveNum,
          [approve]: true
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "点赞失败",
        icon: "none"
      })
    })
  },
  //一级评论更新:
  updateOneLevelComment(id, type) {
    let arr = this.data.commentList;
    let childArr = arr[this.data.oneLevelIndex].child;
    let data = this.data.commentData;
    let obj = {};
    if (type == "main") {
      obj = {
        id: id,
        parentId: data.id,
        openId: app.globalData.openId,
        nickname: app.globalData.nickName,
        avatar: app.globalData.avatar,
        content: this.data.createCommentData.content,
      }
    } else {
      obj = {
        id: id,
        parentId: null,
        openId: app.globalData.openId,
        nickname: app.globalData.nickName,
        avatar: app.globalData.avatar,
        content: this.data.createCommentData.content,
        pnickname: data.nickname,
        pavatar: data.avatar
      }
    }

    childArr.push(obj);
    let kItem = 'commentList[' + this.data.oneLevelIndex + '].child';
    let commentNumber = this.data.commentList[this.data.oneLevelIndex].commentNumber + 1;
    let item = 'commentList[' + this.data.oneLevelIndex + '].commentNumber';
    this.setData({
      [item]: commentNumber,
    })
    this.setData({
      [kItem]: childArr,
    })
  },



  //隐藏评论弹窗:
  hideCommentPop() {
    this.setData({
      isShowCommentPop: false
    })
  },

  //跳转到周边配套页面
  pushToMapAround() {
    let expertItem = this.data.expertArr[0];
    app.globalData.expertData = expertItem;
    //准备报备楼盘信息
    let reportData = {
      houseNumber: this.data.houseDetail.houseNumber,
      name: this.data.houseDetail.name,
      reportCardReq: this.data.houseDetail.reportCardReq,
      reportPhoneReq: this.data.houseDetail.reportPhoneReq,
    }
    app.globalData.reportHouseData = reportData;

    app.globalData.houseLat = this.data.houseDetail.latitude;
    app.globalData.houseLon = this.data.houseDetail.longitude;
    app.globalData.mapHouseAddress = this.data.houseDetail.houseAddress
    wx.navigateTo({
      url: '/newHousePackage/pages/houseMapAround/houseMapAround?name=' + this.data.houseDetail.name + "&houseNumber=" + this.data.houseDetail.houseNumber
    })
  },
  //跳转到楼盘总平页面:
  pushToHouseGeneral() {
    let houseNumber = this.data.houseDetail.houseNumber;
    app.globalData.flatUrl = this.data.houseDetail.flatUrl;
    wx.navigateTo({
      url: '/newHousePackage/pages/houseGeneralPage/houseGeneralPage?houseNumber=' + houseNumber,
    })
  },


  clickCenterPopupOverlay() {
    this.setData({
      showSharePop: false,
      showEmptySharePop: false,
      showRulePopup: false,
      showMealPop: false,
    })
  },



  //底部按钮微信分享:
  bottomWxShare() {
    if (!app.globalData.houseQrCode) {
      wx.showToast({
        title: '暂时无法分享房源',
        icon: "none"
      })
      return;
    }
    let data = this.data.houseDetail;
    let obj = {
      houseName: data.name,
      houseNumber: data.houseNumber,
      coverPic: data.coverPic,
      areaName: data.areaName,
      unitPrice: data.unitPrice,
      totalPrice: data.totalPrice,
      area: data.formatArea,
      qrCode: app.globalData.houseQrCode,
    }
    app.globalData.posterHouse = obj;
    wx.navigateTo({
      url: '/newHousePackage/pages/housePoster/housePoster?type=house',
    })
  },

  //咨询专家:
  askExpertAction() {

    if (this.data.expertArr && this.data.expertArr.length > 0) {
      this.setData({
        showExpertPop: true
      })
    } else {
      wx.showToast({
        title: '暂无咨询专家',
        icon: "none"
      })
    }


  },
  exportPopHidden() {
    this.setData({
      showExpertPop: false
    })
  },
  //置业顾问拨打电话
  exportPhoneClick(e) {
    console.log("JJLog:电话:" + JSON.stringify(e));
    let item = e.detail.item;
    this.commonMakePhone(item);
  },
  //置业顾问聊天
  exportMsgClick(e) {
    console.log("JJLog:聊天:" + JSON.stringify(e));
    let item = e.detail.item;
    if (!app.globalData.isLogin) {
      wx.navigateTo({
        url: '/pages/login/login',
      })
      this.setData({
        showExpertPop: false
      })
      return;
    }
    this.commonExpertChatAction(item);
  },

  //跳转到评论列表去
  pushToMoreComment() {
    let houseNumber = this.data.houseDetail.houseNumber;
    wx.navigateTo({
      url: '/newHousePackage/pages/houseAllComment/houseAllComment?houseNumber=' + houseNumber,
    })
  },
  //跳转到更多楼盘动态去:
  pushToMoreHouseDyn() {
    let houseNumber = this.data.houseDetail.houseNumber;
    wx.navigateTo({
      url: '/newHousePackage/pages/houseAllDyn/houseAllDyn?houseNumber=' + houseNumber + "&isManager=" + 0,
    })
  },
  //复制微信号:
  copyWxChatAction(e) {
    let text = e.currentTarget.dataset.text;
    wx.setClipboardData({
      data: text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '微信号复制成功',
              icon: "none"
            })
          },
          fail: function (err) {
            wx.showToast({
              title: '复制失败',
              icon: "none"
            })
          }
        })
      }
    })
  },
  //咨询置业顾问聊天;
  expertChatAction(e) {
    if (!app.globalData.isLogin) {
      wx.navigateTo({
        url: '/pages/login/login',
      })
      return;
    }
    let item = e.currentTarget.dataset.item;
    this.commonExpertChatAction(item);

  },
  //公共的咨询置业顾问
  commonExpertChatAction(item) {
    this.setData({
      showExpertPop: false,
    })
    let name = "";
    if (item.realName) {
      name = item.realName;
    } else if (item.name) {
      name = item.name;
    }
    else {
      name = item.nickName
    }
    let chatData = {
      name: name,
      avatar: item.avatar,
      chatUserId: item.openId,
      conversationType: "C2C",
      // houseNumber: this.data.houseDetail.houseNumber,
      // houseName: this.data.houseDetail.name,
      // houseCover: this.data.houseDetail.coverPic,
      // housePrice: this.data.houseDetail.totalPrice,
      // houseDesc: this.data.houseDetail.areaName + " | " + "建面" + this.data.houseDetail.formatArea + "㎡",
      // expertId: item.id,
      // expertPhone: item.phone || "",
      // expertWeChat: item.wxChat || "",
    }
    app.globalData.chatData = chatData;
    wx.navigateTo({
      url: '/firstPackage/pages/msgModule/chatRoom/chatRoom',
    })
  },
  //公共的打电话
  commonMakePhone(item) {
    if (item.phone) {
      wx.makePhoneCall({
        phoneNumber: item.phone,
        fail: err => {

        }
      })
      this.setData({
        showExpertPop: false
      })
      // this.expertPhoneActionA(item.id);
    } else {
      wx.showToast({
        title: '暂无电话',
        icon: "none"
      })
      this.setData({
        showExpertPop: false
      })
    }
  },
  expertPhoneAction(e) {
    let item = e.currentTarget.dataset.item;
    this.commonMakePhone(item);
  },
  //用户拨打电话后记录
  expertPhoneActionA(id) {
    expertPhoneAction(id, this.data.houseDetail.houseNumber).then(res => {

    }).catch(res => {

    })
  },
  bottomChatAction() {
    if (this.data.expertArr && this.data.expertArr.length > 0) {
      this.setData({
        showExpertPop: true
      })
    } else {
      wx.showToast({
        title: '暂无客服',
        icon: "none"
      })
    }


  },
  //底部关注或者取关房源:
  bottomCollectAction() {
    let collect = this.data.houseDetail.isCollection;
    this.houseAttentionAction(collect);
  },
  //房源的关注或者取关
  houseAttentionAction(collect) {
    let data = {
      collectType: 1,
      number: this.data.houseDetail.houseNumber
    }
    wx.showLoading();
    attentionAction(data).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        this.setData({
          'houseDetail.isCollection': !collect
        })
        wx.showToast({
          title: collect ? "取关成功" : "关注成功",
          icon: "none"
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:attentionAction", err);
    })
  },
  //跳转到置业顾问详情:
  pushToExpertDetail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/firstPackage/pages/expertModule/newExpertDetail/newExpertDetail?id=' + id,
    })
  },
  //跳转到楼盘更多信息页面
  pushToHouseMoreInfo() {
    let houseNumber = this.data.houseDetail.houseNumber;
    wx.navigateTo({
      url: '/newHousePackage/pages/houseMoreInfo/houseMoreInfo?houseNumber=' + houseNumber,
    })
  },
  //预览项目资料
  previewAttachFile(e) {
    let item = e.currentTarget.dataset.item;
    let url = item.url;
    let type = item.type;
    console.log("JJLog:看看url:" + url);
    console.log("JJLog:看看type==:" + type)
    if (type == 8 || type == 9) {
      var imgArr = []
      imgArr.push(url)
      wx.previewImage({
        current: url,
        urls: imgArr,
      })
    } else {
      let typeText = "doc";
      switch (type) {
        case 1:
          typeText = "doc";
          break;
        case 2:
          typeText = "docx";
          break;
        case 3:
          typeText = "xls";
          break;
        case 4:
          typeText = "xlsx";
          break;
        case 5:
          typeText = "ppt";
          break;
        case 6:
          typeText = "pptx";
          break;
        case 7:
          typeText = "pdf";
          break;
        default:
          break;
      }
      wx.showLoading();
      wx.downloadFile({
        url: url,
        success: function (res) {
          wx.hideLoading();
          console.log("JJLog:下载文件成功:" + JSON.stringify(res));
          if (res.statusCode === 200) {
            var Path = res.tempFilePath
            wx.openDocument({
              fileType: typeText,
              filePath: Path,
              success: function (res) {
                console.log('打开 PDF 成功');
              }
            })
          }
        },
        fail: function (res) {
          wx.hideLoading();
          wx.showToast({
            title: '预览文件失败',
            icon: "none"
          })
          console.log("JJLog:预览文件失败:" + JSON.stringify(res));
        }
      })
    }
  },
  //跳转到注册页面
  pushToLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  //跳转到入驻页面:
  pushToEnter() {
    wx.navigateTo({
      url: '/formPackage/pages/enterApply/enterApplyMain/enterApplyMain',
    })
  },
  //公司入驻为房源代理跳转:
  companyEnterHouseAction() {
    if (this.data.roleType == 7) {
      wx.showModal({
        title: '提示',
        content: '您当前不是公司角色，确认开通公司角色?',
        confirmColor: "#FF0000",
        success: res => {
          if (res.confirm) {
            wx.navigateTo({
              url: '/formPackage/pages/enterApply/companyApply/companyApply',
            })
          }
        }
      })
      return;
    }
    if (this.data.roleType == 9) {
      wx.navigateTo({
        url: '/formPackage/pages/commissionManager/addNewCommission/addNewCommission?houseNumber=' + this.data.houseDetail.houseNumber,
      })
    }



  },

  //底部跳转报备:
  bottomReportAction() {
    // if (this.data.houseDetail.isCloseReport) {
    //   //是否关闭当前楼盘报备
    //   wx.showModal({
    //     title: '提示',
    //     content: '当前楼盘暂时无法报备，请联系客服咨询',
    //     showCancel: false,
    //     confirmColor: "#FF0000",
    //     success: res => {
    //       if (res.confirm) {

    //       }
    //     }
    //   })
    //   return;
    // }
    //准备报备楼盘信息
    let reportData = {
      houseNumber: this.data.houseDetail.houseNumber,
      name: this.data.houseDetail.name,
      reportCardReq: this.data.houseDetail.reportCardReq,
      reportPhoneReq: this.data.houseDetail.reportPhoneReq,
      companyName: "",
      companyNumber: "",
    }
    app.globalData.reportHouse = reportData;
    wx.switchTab({
      url: '/pages/report/report',
    })
  },

  //上面直接点击公司的报备:
  companyReportAction(e) {
    let item = e.currentTarget.dataset.item;
    console.log("JJLog:" + JSON.stringify(item));
    let reportData = {
      houseNumber: this.data.houseDetail.houseNumber,
      name: this.data.houseDetail.name,
      reportCardReq: this.data.houseDetail.reportCardReq,
      reportPhoneReq: this.data.houseDetail.reportPhoneReq,
      companyName: item.companyName,
      companyNumber: item.companyNumber,
      commissionName: item.name,
      commission: item.commission
    }
    app.globalData.reportHouse = reportData;
    wx.switchTab({
      url: '/pages/report/report',
    })
  },

  // 跳转到全部图片页面:
  pushToAllImgs() {
    let houseNumber = this.data.houseDetail.houseNumber;
    wx.navigateTo({
      url: '/newHousePackage/pages/houseAllImgs/houseAllImgs?houseNumber=' + houseNumber,
    })
  },
  //跳转到对应佣金
  pushToCommissionDetail(e) {
    let id = e.currentTarget.dataset.id;
    if (this.data.zhuChangeArr && this.data.zhuChangeArr.length > 0) {
      app.globalData.zcData = this.data.zhuChangeArr[0];
    }
    wx.navigateTo({
      url: '/firstPackage/pages/commissionModule/commissionDetail/commissionDetail?id=' + id,
    })
  },

  //变价提醒和售卖提醒操作
  changeSubRemindAction(e) {
    let type = e.currentTarget.dataset.type;
    if (!app.globalData.isBindMp) {
      wx.showToast({
        title: '关注官方公众号后，才能订阅提醒',
        icon: "none",
        duration: 3000
      })
      setTimeout(() => {
        wx.navigateTo({
          url: '/firstPackage/pages/officialAccounts/officialAccounts',
        })
      }, 3000);
      return;
    }
    this.settingHouseRemind(type);
  },
  //提醒操作:
  settingHouseRemind(type) {
    wx.showLoading();
    settingHouseRemind(this.data.houseNumber, type).then(res => {
      wx.hideLoading();
      console.log("JJLog:提醒操作:" + JSON.stringify(res));
      if (res.code == 200) {
        if (type == 1) {
          let isSubscriptionChangePrice = this.data.houseDetail.isSubscriptionChangePrice ? false : true;
          if (isSubscriptionChangePrice) {
            this.setData({
              changePriceTitle: "取消变价提醒"
            })
          } else {
            this.setData({
              changePriceTitle: "变价提醒"
            })
          }
          this.setData({
            'houseDetail.isSubscriptionChangePrice': isSubscriptionChangePrice
          })
        } else {
          let isSubscriptionOpen = this.data.houseDetail.isSubscriptionOpen ? false : true;
          if (isSubscriptionOpen) {
            this.setData({
              changeOpenTimeTitle: "取消售卖提醒"
            })
          } else {
            this.setData({
              changeOpenTimeTitle: "售卖提醒"
            })
          }
          this.setData({
            'houseDetail.isSubscriptionOpen': isSubscriptionOpen
          })
        }
        wx.showToast({
          title: '操作成功',
          icon: "success"
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:settingHouseRemind", err);
    })
  },

  //scrollView下拉刷新
  refreshDownData() {
    this.setData({
      scrollRefreshStatus: true
    })

    this.queryBaseDetail();
  },

  //回到首页
  backHomeAction() {
    wx.switchTab({
      url: '/pages/home/home',
    })
  },
  onScroll(event) {
    wx.createSelectorQuery()
      .select('#scroller')
      .boundingClientRect((res) => {
        this.setData({
          scrollTop: event.detail.scrollTop,
          offsetTop: res.top,
        });
      })
      .exec();
  },
  //滚动点击:
  horizontalTapAction(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      horizontalSwiperIndex: index
    })
  },
  //底部预约楼盘
  bottomBookingAction() {
    let houseName = this.data.houseDetail.name;
    let houseNumber = this.data.houseDetail.houseNumber;
    wx.navigateTo({
      url: '/formPackage/pages/appointment/myAppointment/myAppointment?houseName=' + houseName + "&houseNumber=" + houseNumber,
    })
  },
  createNewShareTeamAction() {
    this.setData({
      showSharePop: false,
      showEmptySharePop: true
    })
  },
  keyBoardHeightChange(e) {
    let height = e.detail.height;
    console.log("JJLog:高度变化时:" + height)
    this.setData({
      keyBoardHeight: height,
    })
  },
  // swiperItemClick(e) {
  //   let url = e.currentTarget.dataset.url;
  //   let arr = e.currentTarget.dataset.arr;
  //   let urls = [];
  //   arr.forEach((item) => {
  //     urls.push(item.url)
  //   })
  //   wx.previewImage({
  //     current: url,
  //     urls: urls,
  //   })
  // },

  //预览视频:
  previewImgOrVideo() {
    //视频
    let videoUrl = this.data.videoArr[0].url;
    app.globalData.videoUrl = videoUrl;
    wx.navigateTo({
      url: '/pages/videoPlay/videoPlay',
    })
  },
  //预览图片:
  previewImgAction(e) {
    let url = e.currentTarget.dataset.url;
    let arr = e.currentTarget.dataset.arr;
    let urls = [];
    arr.forEach((item) => {
      urls.push(item.url);
    })
    wx.previewImage({
      current: url,
      urls: urls,
    })
  },
  // 户型顶部切换:
  houseTypeChangeAction(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      houseTypeIndex: index
    })
    if (index == 0) {
      this.setData({
        topBanners: this.data.videoArr,
        currentSwiperIndex: 0
      })
    } else {
      this.setData({
        topBanners: this.data.allTopImgArr,
        currentSwiperIndex: 0
      })
      // console.log("JJLog:topBanners:" + JSON.stringify(this.data.topBanners));
    }
  },
  //跳转到更多专家列表:
  pushToMoreExpertListAction() {
    let houseNumber = this.data.houseDetail.houseNumber;
    if (this.data.expertArr && this.data.expertArr.length == 3) {
      wx.navigateTo({
        url: '/newHousePackage/pages/newHouseExpertList/newHouseExpertList?houseNumber=' + houseNumber,
      })
    }

  },

  //滑动监听
  bindscrollAction(e) {
    // console.log("JJLog:滚动监听:" + JSON.stringify(e));
    let scrollTopValue = e.detail.scrollTop;
    this.setData({
      scrollTopValue: scrollTopValue,
    })
  },

  //查看佣金弹窗
  seeRuleDetailAction(e) {
    let text = e.currentTarget.dataset.text;
    let title = e.currentTarget.dataset.title;
    this.setData({
      showRuleContent: text,
      showPopupTitle: title,
      showRulePopup: true
    })
  },

  //顶部功能模块跳转:
  pushToEnterMAction(e) {
    let item = e.currentTarget.dataset.item;
    let url = item.url;
    let houseNumber = this.data.houseDetail.houseNumber;
    if (item.title == "周边配套") {
      this.pushToMapAround();
      return;
    }
    if (item.title == "全部户型") {
      if (this.data.houseTypeChangeArr && this.data.houseTypeChangeArr.length < 1) {
        wx.showToast({
          title: '该楼盘暂无户型信息',
          icon: "none"
        })
      } else {
        wx.navigateTo({
          url: url + '?houseNumber=' + houseNumber,
        })
      }
      return;
    }
    wx.navigateTo({
      url: url + '?houseNumber=' + houseNumber,
    })
  },


  //绑定房源操作:
  bindHouseAction() {
    if (this.data.roleType == 7) {
      //经纪人绑定:
      // wx.showModal({
      //   title: '提示',
      //   content: '确认入驻为该房源经纪人?',
      //   confirmColor: "#FF0000",
      //   success: res => {
      //     if (res.confirm) {
      //       this.agentEnterNewHouse();
      //     }
      //   }
      // })
      wx.navigateTo({
        url: '/formPackage/pages/platformModule/agentEnterHouseApply/agentEnterHouseApply?houseNumber=' + this.data.houseDetail.houseNumber,
      })
    } else if (this.data.roleType == 9) {
      //公司绑定:
      wx.navigateTo({
        url: '/formPackage/pages/commissionManager/addNewCommission/addNewCommission?houseNumber=' + this.data.houseDetail.houseNumber,
      })
    }
  },

  //经纪人入驻房源接口调用:
  agentEnterNewHouse() {
    wx.showLoading();
    agentEnterNewHouse(this.data.houseDetail.houseNumber).then(res => {
      wx.hideLoading();
      if (res.code == 200) {

      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:agentEnterNewHouse", err);
    })
  },
  //入驻专家点击;
  expertEnterHouseAction() {
    // if (!this.data.isLogin) {
    //   wx.navigateTo({
    //     url: '/pages/login/login',
    //   })
    //   return;
    // }
    wx.navigateTo({
      url: '/formPackage/pages/platformModule/agentEnterHouseApply/agentEnterHouseApply?houseNumber=' + this.data.houseDetail.houseNumber,
    })
    if (this.data.isLogin && this.data.roleType == 1) {
      //已经登录但是是普通人的时候:
      wx.navigateTo({
        url: '/formPackage/pages/enterApply/agentApply/agentApply',
      })
      return;
    }
    //已经是经纪人或者公司角色
    if (this.data.roleType == 7 || this.data.roleType == 9) {
      wx.navigateTo({
        url: '/formPackage/pages/platformModule/agentEnterHouseApply/agentEnterHouseApply?houseNumber=' + this.data.houseDetail.houseNumber,
      })
    }
  },

  //代理公司驻场点击:
  residentShowPopAction(e) {
    let item = e.currentTarget.dataset.item;
    // console.log("JJLog:item=" + JSON.stringify(item));
    this.setData({
      selectCompanyNumber: item.companyNumber
    })
    this.queryCompanyHouseResident();
  },
  //查询代理公司的驻场员工:
  queryCompanyHouseResident() {
    wx.showLoading();
    queryCompanyHouseResident(this.data.selectCompanyNumber, this.data.houseDetail.houseNumber).then(res => {
      wx.hideLoading();
      console.log("JJLog:查询到的驻场是:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          residentArr: res.data || []
        })
        if (res.data && res.data.length > 0) {
          this.setData({
            showExpertPop: true,
            expertArr: this.data.residentArr
          })
        } else {
          wx.showToast({
            title: '暂无代理驻场',
            icon: "none"
          })
        }
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
      console.error("JJLog:queryCompanyHouseResident", err);
    })
  },

  //跳转到小区详情:
  pushToCommunityDetail() {
    if (!this.data.communityNumber) {
      wx.showToast({
        title: '该房源暂无关联小区',
        icon: "none",
        duration: 3000
      })
      return;
    }
    wx.navigateTo({
      url: '/secondHousePackage/pages/smallCommunityDetail/smallCommunityDetail?communityNumber=' + this.data.communityNumber,
    })

  },





  //跳转到分享海报页面
  pushToSharePage() {
    // if (!app.globalData.houseQrCode) {
    //   wx.showToast({
    //     title: '暂时无法分享房源',
    //     icon: "none"
    //   })
    //   return;
    // }
    let data = this.data.houseDetail;
    let obj = {
      houseName: data.titleDesc,
      houseNumber: data.houseNumber,
      coverPic: data.coverPic,
      areaName: data.areaName || "暂无",
      totalPrice: data.totalPrice,
      area: data.area,
      qrCode: app.globalData.houseQrCode,
    }
    app.globalData.posterHouse = obj;
    wx.navigateTo({
      url: '/newHousePackage/pages/housePoster/housePoster?type=secondHouse',
    })
  },
  //房源关注操作:
  attentionHouseAction() {
    let data = {
      collectType: 2,
      number: this.data.houseDetail.houseNumber
    }
    let collect = this.data.houseDetail.isCollect;
    wx.showLoading();
    attentionAction(data).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        this.setData({
          'houseDetail.isCollect': !collect
        })
        wx.showToast({
          title: collect ? "取关成功" : "关注成功",
          icon: "none"
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:attentionAction", err);
    })
  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let path = "";
    path = "/shopMallPackage/pages/newBaseDetail/newBaseDetail?isShare=1" + "&userId=" + app.globalData.userId + "&houseNumber=" + this.data.houseDetail.id

    return {
      title: this.data.houseDetail.title || app.globalData.commonShareTitle,
      path: path
    }
  },
  onShareTimeline: function () {
    return {
      title: this.data.houseDetail.title || app.globalData.commonShareTitle,
      query: "isFriend=1" + "&userId=" + app.globalData.userId + "&houseNumber=" + this.data.houseDetail.id,
      imageUrl: this.data.houseDetail.coverPic
    }
  },
})